<!-- 投递简历 -->
<template>
  <div>
    <div class="card" v-for="item in recode" :key="item.id">
      <a href="#">
        <div class="title">{{ item.job_name }}</div>
        <div class="company">
          <span class="company-name">
            <el-icon :size="16" class="com-img">
              <i-ep-OfficeBuilding />
            </el-icon>
            {{ item.company_name }}</span>
        </div>
        <div class="salary">{{ item.job_salary }}</div>
        <el-button @click="cancel(item.id)" class="cancelBtn" type="danger" round size="small">取消投递</el-button>
      </a>
    </div>
  </div>
</template>
<script setup>
import {ref, inject} from "vue";
import {watch} from "vue";
import checkLoginStatus from "@/hooks/checkLoginStatus.js";
import {useRouter} from "vue-router";
import login from "@/hooks/login.js";

const router = useRouter()
const $axios = inject("$axios")
const $root = inject("$root")
const recode = ref([])
/**
 * 获取用户投递记录
 */
const getRecode = () => {
  console.log("获取用户投递记录")
  $axios.get($root + '/postresume/').then((res) => {
    console.log(res)
    if (res.data.code == 200) {
      recode.value = res.data.data
    }
  })
}

/**
 * 取消投递
 */
const cancel=(id)=>{
  $axios.post($root + `/postresume/cancel/${id}/` ).then((res) => {
    if (res.data.code == 200) {
      //重新获取投递记录
      getRecode()
    }
  })
}



/**
 * 监听路由变化，判断是否需要重新登录;
 */
watch(() => router.currentRoute.value.name, (name) => {
      // 如果当前路由的名称是"recode"，并且没有登录
      if (name == "recode" && !checkLoginStatus()) {
        // 调用checkLoginStatus函数，传入getRecode和login函数作为参数
        checkLoginStatus(getRecode, login)
      }
    },// 立即触发监听器
    {immediate: true, deep: true})
</script>

<style scoped>
.cancelBtn {
  position: absolute;
  bottom: 15px;
  right: 8px;
}

.com-img {
  position: relative;
  top: 4px;
}
</style>